#include "stdio.h"
void quitsort(int *array,int high,int low);
void display(int *array,int length);
void main()
{
	int array[15]={19,3,4,23,21,53,34,65,29,13,34,34,89,54,42};
	display(array,15);
	quitsort(array,14,0);
	display(array,15);
}

void display(int *array,int length)
{
	int i=0;
	while(i<length)
	{
		printf ("%d   ",array[i++]);
	}
	printf("\n");
}

void swap(int *array,int i,int j)
{
	int tmp = array[i];
	array[i] = array[j];
	array[j] = tmp;
}

void quitsort(int *array,int high,int low)
{
	int l=low,h=high;
	int tmp = array[low];
	while(l < h)
	{
		while(l < h)
		{
			if( array[l] > tmp )
			{
				swap(array,l,h);
				--h;
				break;
			}
			++l;
		}
		while(l < h)
		{
			if(array[h] < tmp)
			{
				swap(array,l,h);
				++l;
				break;
			}
			--h;
		}
	}
	if(array[l] > tmp)
	{
		--l;
	}
	swap(array,l,low);
	display(array,15);
	if(low < l)
		quitsort(array,l-1,low);
	if(l < high)
		quitsort(array,high,l+1);
}
